﻿﻿using DeviceCommons.DeviceMessages.Serialization;
using DeviceCommons.DeviceMessages.Serialization.V1.Serializers;

namespace DeviceCommons.DataHandling
{
    public static class DeviceMessageSerializerProvider
    {
        public static readonly IDeviceMessageSerializer MessageSer = new DeviceMessageSerializer();
        
        // 为了向后兼容性，全局Parser实例配置默认解密函数
        public static readonly IDeviceMessageParser MessagePar = CreateDefaultParser();
        
        /// <summary>
        /// 创建配置了默认解密函数的Parser实例
        /// </summary>
        /// <returns>配置好的Parser实例</returns>
        private static IDeviceMessageParser CreateDefaultParser()
        {
            var parser = new DeviceMessageParser();
            // 配置默认解密函数以保持向后兼容性
            parser.DecryptFunc = cipherText => DeviceMessageUtilities.AES.Value.Decrypt(cipherText, DeviceMessageArrayPool.DefaultAedPassword);
            return parser;
        }

        
        public static readonly IDeviceMessageHeaderParser HeaderPar = new DeviceMessageHeaderParser();

        #region V1
        public static readonly IDeviceMessageHeaderSerializer HeaderV1Ser = new DeviceMessages.Serialization.V1.Serializers.DeviceMessageHeaderSerializer();

        public static readonly IDeviceMessageInfoSerializer InfoV1Ser =
            new DeviceMessages.Serialization.V1.Serializers.DeviceMessageInfoSerializer();
        public static readonly IDeviceMessageInfoParser InfoV1Par =
            new DeviceMessages.Serialization.V1.Parsers.DeviceMessageInfoParser();

        public static readonly IDeviceMessageInfoReadingsSerializer InfoReadingsV1Ser =
            new DeviceMessages.Serialization.V1.Serializers.DeviceMessageInfoReadingsSerializer();
        public static readonly IDeviceMessageInfoReadingsParser InfoReadingsV1Par =
            new DeviceMessages.Serialization.V1.Parsers.DeviceMessageInfoReadingsParser();

        public static readonly IDeviceMessageInfoReadingSerializer InfoReadingV1Ser =
            new DeviceMessages.Serialization.V1.Serializers.DeviceMessageInfoReadingSerializer();
        public static readonly IDeviceMessageInfoReadingParser InfoReadingV1Par =
            new DeviceMessages.Serialization.V1.Parsers.DeviceMessageInfoReadingParser();

        public static readonly IDeviceMessageInfoReadingStatesSerializer InfoReadingStatesV1Ser =
            new DeviceMessages.Serialization.V1.Serializers.DeviceMessageInfoReadingStatesSerializer();
        public static readonly IDeviceMessageInfoReadingStatesParser InfoReadingStatesV1Par =
            new DeviceMessages.Serialization.V1.Parsers.DeviceMessageInfoReadingStatesParser();

        public static readonly IDeviceMessageInfoReadingStateSerializer InfoReadingStateV1Ser =
            new DeviceMessages.Serialization.V1.Serializers.DeviceMessageInfoReadingStateSerializer();
        public static readonly IDeviceMessageInfoReadingStateParser InfoReadingStateV1Par =
            new DeviceMessages.Serialization.V1.Parsers.DeviceMessageInfoReadingStateParser();

        public static readonly IDeviceMessageChildSerializer ChildV1Ser =
            new DeviceMessages.Serialization.V1.Serializers.DeviceMessageChildSerializer();
        public static readonly IDeviceMessageChildParser ChildV1Par =
            new DeviceMessages.Serialization.V1.Parsers.DeviceMessageChildParser();
        #endregion

        #region V2
        public static readonly IDeviceMessageHeaderSerializer HeaderV2Ser = new DeviceMessages.Serialization.V2.Serializers.DeviceMessageHeaderSerializer();

        public static readonly IDeviceMessageInfoSerializer InfoV2Ser =
            new DeviceMessages.Serialization.V2.Serializers.DeviceMessageInfoSerializer();
        public static readonly IDeviceMessageInfoParser InfoV2Par =
            new DeviceMessages.Serialization.V2.Parsers.DeviceMessageInfoParser();

        public static readonly IDeviceMessageInfoReadingsSerializer InfoReadingsV2Ser =
            new DeviceMessages.Serialization.V2.Serializers.DeviceMessageInfoReadingsSerializer();
        public static readonly IDeviceMessageInfoReadingsParser InfoReadingsV2Par =
            new DeviceMessages.Serialization.V2.Parsers.DeviceMessageInfoReadingsParser();

        public static readonly IDeviceMessageInfoReadingSerializer InfoReadingV2Ser =
            new DeviceMessages.Serialization.V2.Serializers.DeviceMessageInfoReadingSerializer();
        public static readonly IDeviceMessageInfoReadingParser InfoReadingV2Par =
            new DeviceMessages.Serialization.V2.Parsers.DeviceMessageInfoReadingParser();

        public static readonly IDeviceMessageInfoReadingStatesSerializer InfoReadingStatesV2Ser =
            new DeviceMessages.Serialization.V2.Serializers.DeviceMessageInfoReadingStatesSerializer();
        public static readonly IDeviceMessageInfoReadingStatesParser InfoReadingStatesV2Par =
            new DeviceMessages.Serialization.V2.Parsers.DeviceMessageInfoReadingStatesParser();

        public static readonly IDeviceMessageInfoReadingStateSerializer InfoReadingStateV2Ser =
            new DeviceMessages.Serialization.V2.Serializers.DeviceMessageInfoReadingStateSerializer();
        public static readonly IDeviceMessageInfoReadingStateParser InfoReadingStateV2Par =
            new DeviceMessages.Serialization.V2.Parsers.DeviceMessageInfoReadingStateParser();

        public static readonly IDeviceMessageChildSerializer ChildV2Ser =
            new DeviceMessages.Serialization.V2.Serializers.DeviceMessageChildSerializer();
        public static readonly IDeviceMessageChildParser ChildV2Par =
            new DeviceMessages.Serialization.V2.Parsers.DeviceMessageChildParser(); 
        #endregion


    }
}
